/*表格渲染*/
var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];

function orderList(data) {
    console.log(data)
    dataSource.splice(0, dataSource.length);//清空数组
if(data.data!=null){
    $.each(data.data,function (i, field) {
        var rowData = new Array();
        rowData.push(field.parentCustomerCode)
        rowData.push(field.parentCustomerName);
        rowData.push(field.totalCount);
        rowData.push(field.systemErrorCount);  //row[3] 系统异常30 row[4] 非我司客户50 row[5]非正常商品60 row[6]地址异常70 row[7]运费异常80
        rowData.push(field.projectIdErrorCount);
        rowData.push(field.goodsErrorCount);
        rowData.push(field.addressErrorCount);
        rowData.push(field.freightSettingErrorCount);
        dataSource.push(rowData);
    });
}

    initDataTable(dataSource);

    function initDataTable(dataSource) {
        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            "autoWidth": false,
            "ordering": false,
            "paging": false,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": [5, 10, 25, 50],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />",
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[1];
                        return val;
                    },
                    "targets": 0
                },
                //未完成订单总数
                {
                    "render": function (data, type, row, meta) {
                        var val = row[2];
                        return val;
                    },
                    "targets": 1
                },
                //非我司客户
                {
                    "render": function (data, type, row, meta) {
                        var val = '<span class=""><a onclick="exceptionOrder(\'未完成订单管理\',\'channelExceptionOrder.html\',\''+row[0]+'\',\''+row[1]+'\',30)">'+row[3]+'</a></span>';
                        return val;
                    },
                    "targets":2
                },
                //非正常商品
                {
                    "render": function (data, type, row, meta) {
                        var val = '<span class=""><a onclick="exceptionOrder(\'未完成订单管理\',\'channelExceptionOrder.html\',\''+row[0]+'\',\''+row[1]+'\',50)">'+row[4]+'</a></span>';
                        return val;
                    },
                    "targets":3
                },
                //收货地址异常
                {
                    "render": function (data, type, row, meta) {
                        var val = '<span class=""><a onclick="exceptionOrder(\'未完成订单管理\',\'channelExceptionOrder.html\',\''+row[0]+'\',\''+row[1]+'\',60)">'+row[5]+'</a></span>';
                        return val;
                    },
                    "targets":4
                },
                //渠道运费设置异常
                {
                    "render": function (data, type, row) {
                        var val = '<span class=""><a onclick="exceptionOrder(\'未完成订单管理\',\'channelExceptionOrder.html\',\''+row[0]+'\',\''+row[1]+'\',70)">'+row[6]+'</a></span>';
                        return val;
                    },
                    "targets": 5
                },
                //系统异常
                {
                    "render": function (data, type, row) {
                        var val = '<span class=""><a onclick="exceptionOrder(\'未完成订单管理\',\'channelExceptionOrder.html\',\''+row[0]+'\',\''+row[1]+'\',80)">'+row[7]+'</a></span>';
                        return val;
                    },
                    "targets": 6
                },
            ]
        });
        //权限控制函数
       // power()
    }
}

getList()
function getList(){
    var per={}
            /*per = {
                pageNum: 1, //当前页码
                pageSize: 20,//每页显示条数
                "customerCode":$("#ascription_lsit").val(),//渠道商id
                "channelOrderId":$("#dorderCode").val(),
                "orderId":$("#orderCode").val(),
                "skuCode":$("#SKUCode").val(),
                "orderStatus":$("#dealState").val(),
                "exceptionType":$("#exceptionType").val(),
                "createdOrderAtStart":$("#timemin").val(),
                "createdOrderAtEnd":$("#timemax").val(),
                "pushOrderAtStart":$("#tuisongmin").val(),
                "pushOrderAtEnd":$("#tuisongmax").val(),
                "receiverName":$("#consignee").val(),
                "receiverTelephone":$("#phoneNum").val(),
                "receiverProvince":$("#getArea").val(),
                "receiverCity":$("#getPlace").val(),
                "sentType":$("#sent_type").val(),
            };*/

    $.ajax({
        contentType: "application/json",
        type: "POST",
        url: root.dockingplatform.allFailedPreOrderCount,
        cache: false,  //禁用缓存
        dataType: "json",
        data: JSON.stringify(per),
        success: function (result) {
            orderList(result);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
        }
    });
}
/*跳转订单详情*/
function exceptionOrder(title,url,customerCode,customerName,exception){
    sessionStorage.setItem("customerCode",customerCode);
    sessionStorage.setItem("customerName",customerName);
    console.log("====="+customerName);
    sessionStorage.setItem("exception",exception);
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}